import { getActivity, getActivityList, participateActivity, cancelActivityParticipation } from "../api/activity";

export const activity = {
  async getActivity(id) {
    try {
      let result = await getActivity(id);
      return result.data;
    } catch (err) {
      uni.showToast({
        title: "获取活动详情失败, 请检查网络",
        icon: "error"
      });
    }
  },
  async getActivityList(cursor, limit) {
    try {
      let result = await getActivityList(cursor ? cursor : '', limit);
      return result.data;
    } catch (err) {
      uni.showToast({
        title: "获取活动列表失败, 请检查网络",
        icon: "error"
      });
    }
  },
  async participateActivity(activityId) {
    try {
      let result = await participateActivity(activityId);
      return result.msg;
    } catch (err) {
      uni.showToast({
        title: "参与活动失败, 请检查网络",
        icon: "error"
      });
    }
  },
  async cancelActivityParticipation(activityId) {
    try {
      let result = await cancelActivityParticipation(activityId);
      return result.msg;
    } catch (err) {
      uni.showToast({
        title: "取消参与活动失败, 请检查网络",
        icon: "error"
      });
    }
  }
}